#ifndef __PVMOVDATASOURCE_H__
#define __PVMOVDATASOURCE_H__

#include "pvm/pvmapi.h"
#include "lib/pvmsystem.h"
#include "lib/decoders/oggvorbis/pvmoggincludes.h"

#include "lib/memory/pvmmemory.h"

class IPvmInStream;

class PVMOVDataSource : public PVMAllocableObject
{
protected:
	IPvmInStream*	stream;
	OggVorbis_File	ov;
	pvm_bool		ovOpened;
	pvm_int				refCount;
	PVMCriticalSection critical;
	pvm_bool		criticalInitialized;

protected:
	PVMOVDataSource();

	size_t ReadFunc(void *ptr, size_t size, size_t nmemb);
	pvm_bool SeekFunc(pvm_int64 offset, int whence);
	pvm_int CloseFunc();
	long TellFunc();

public:
	virtual ~PVMOVDataSource();

	static PVMOVDataSource* Create(IPvmInStream* srcStream, bool copyStream);

	int GetRefCount();
	int Release();
	int AddRef();

	IPvmInStream&	Stream();
	OggVorbis_File&	OVFile();

	friend size_t pvm_ov_read_func(void *ptr, size_t size, size_t nmemb, void *datasource);
	friend int pvm_ov_seek_func(void *datasource, pvm_int64 offset, int whence);
	friend int pvm_ov_close_func(void *datasource);
	friend long   pvm_ov_tell_func(void *datasource);
};

#endif
